//
//  DetailViewController.m
//  ItaliaStraordinaria
//
//  
//  Copyright (c) 2012 __InDuoWeb__. All rights reserved.
//

#import "NewsDetailViewController.h"
#import "AppDelegate.h"

@implementation NewsDetailViewController
@synthesize titleNewsDisplay;
@synthesize descriptionNewsDisplay;
@synthesize imgNewsDisplay;
@synthesize theList;

AppDelegate *app;

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.title = theList.name;
    [[UIBarButtonItem appearance] setTintColor:[UIColor orangeColor]];

    app = [[UIApplication sharedApplication] delegate];
    
    
    //  To catch img address without first "/n"
    NSString *old_Stra_Photo = theList.first_image_big;
    NSString *path = [old_Stra_Photo stringByTrimmingCharactersInSet:[NSCharacterSet newlineCharacterSet]];
    NSURL *url = [NSURL URLWithString:path];
    NSData *data = [NSData dataWithContentsOfURL:url];
    UIImageView *subview = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f,320.0f, 460.0f)];
    [subview setImage:[UIImage imageWithData:data]];
    
    [imgNewsDisplay addSubview:subview];
    self.titleNewsDisplay.text = theList.name;
    self.descriptionNewsDisplay.text = theList.description;
       
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 22;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)theTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
	
	switch(indexPath.section)
	{
		case 0:
			cell.textLabel.text = theList.name;
			break;
		case 1:
			cell.textLabel.text = theList.abstract;
			break;
		case 2:
			cell.textLabel.text = theList.info1;
			break;
        case 3:
			cell.textLabel.text = theList.info2;
			break;
        case 4:
			cell.textLabel.text = theList.description;
			break;
        case 5:
			cell.textLabel.text = theList.address_street;
			break;
        case 6:
			cell.textLabel.text = theList.address_street_number;
			break;
        case 7:
			cell.textLabel.text = theList.address_zip;
			break;
        case 8:
			cell.textLabel.text = theList.address_city;
			break;
        case 9:
			cell.textLabel.text = theList.address_region;
			break;
        case 10:
			cell.textLabel.text = theList.address_province;
			break;
        case 11:
			cell.textLabel.text = theList.address_latitude;
			break;
        case 12:
			cell.textLabel.text = theList.address_longitude;
			break;
        case 13:
			cell.textLabel.text = theList.category;
			break;
        case 14:
			cell.textLabel.text = theList.sub_category;
			break;
        case 15:
			cell.textLabel.text = theList.stra_name;
			break;
        case 16:
            cell.textLabel.text = theList.stra_photo;
			break;
        case 17:
			cell.textLabel.text = theList.first_image_big;
			break;
        case 18:
			cell.textLabel.text = theList.has_other_images;
			break;
        case 19:
			cell.textLabel.text = theList.video;
			break;
        case 20:
			cell.textLabel.text = theList.id;
			break;
        case 21:
			cell.textLabel.text = theList.has_products;
			break;
	}
	
	return cell;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
	
	NSString *sectionName = nil;
	
	switch(section)
	{
		case 0:
			sectionName = @"Name";
			break;
		case 1:
			sectionName = @"Abstract";
			break;
		case 2:
			sectionName = @"Info1";
			break;
        case 3:
			sectionName = @"Info2";
			break;
        case 4:
			sectionName = @"Description";
			break;
        case 5:
			sectionName = @"Street";
			break;
        case 6:
			sectionName = @"Street Number";
			break;
        case 7:
			sectionName = @"Zip";
			break;
        case 8:
			sectionName = @"City";
			break;
        case 9:
			sectionName = @"Region";
			break;
        case 10:
			sectionName = @"Province";
			break;
        case 11:
			sectionName = @"Latitude";
			break;
        case 12:
			sectionName = @"Longitude";
			break;
        case 13:
			sectionName = @"Category";
			break;
        case 14:
			sectionName = @"Sub_category";
            break;
        case 15:
			sectionName = @"Stra_name";
			break;
        case 16:
			sectionName = @"Stra_photo";
			break;
        case 17:
			sectionName = @"First_image_big";
			break;
        case 18:
			sectionName = @"Has_Other_Images";
			break;
        case 19:
			sectionName = @"Video";
			break;
        case 20:
			sectionName = @"ID";
			break;
        case 21:
			sectionName = @"Has_Products";
			break;
    }
	
	return sectionName;
}							
- (void)viewDidUnload {
    [self setTitleNewsDisplay:nil];
    [self setDescriptionNewsDisplay:nil];
    [self setImgNewsDisplay:nil];
    [super viewDidUnload];
}
@end
